﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SanctusSoftware.Music.ChordSheetEditor.Client;
using Microsoft.Office.Interop.Word;

namespace SanctusSoftware.Music.ChordSheetEditor.Word
{
  public class WordFont : IFont
  {

    #region Fields

    private readonly Font _Font;

    #endregion

    #region Properties

    public string Name
    {
      get
      {
        return _Font.Name;
      }
      set
      {
        _Font.Name = value;
      }
    }

    public decimal Size
    {
      get
      {
        return Convert.ToDecimal(_Font.Size);
      }
      set
      {
        _Font.Size = Convert.ToSingle(value);
      }
    }

    private RichTextFormatColor[] _AvailableColors;
    public RichTextFormatColor[] AvailableColors
    {
      get 
      {
        if (_AvailableColors == null)
        {
          _AvailableColors = RichTextFormatColorHelper.AvailableColors;
        }
        return _AvailableColors; 
      }
      set { _AvailableColors = value; }
    }

    public RichTextFormatColor Color
    {
      get
      {
        return AvailableColors.FirstOrDefault(item => (WdColor)item.Tag == _Font.Color);
      }
      set
      {
        if (value == null)
        {
          _Font.Color = WdColor.wdColorAutomatic;
        }
        else
        {
          _Font.Color = (WdColor)value.Tag;
        }
      }
    }

    public bool Bold
    {
      get
      {
        return (_Font.Bold == 1);
      }
      set
      {
        _Font.Bold = value ? 1 : 0;
      }
    }

    public bool Italic
    {
      get
      {
        return (_Font.Italic == 1);
      }
      set
      {
        _Font.Italic = value ? 1 : 0;
      }
    }

    public bool Underline
    {
      get
      {
        return (_Font.Underline == WdUnderline.wdUnderlineWords);
      }
      set
      {
        _Font.Underline = value ? WdUnderline.wdUnderlineWords : WdUnderline.wdUnderlineNone;
      }
    }

    #endregion

    #region Constructor

    public WordFont(Font font)
    {
      _Font = font;
    }

    #endregion


    
  }
}
